<!--
 * @Author: anshengtyp
 * @Date: 2023-11-30 17:10:50
 * @LastEditTime: 2023-12-05 08:11:56
 * @LastEditors: anshengtyp
 * @Description:前端添加质检记录
-->
<template>
  <el-dialog :modal="false" :title="title" :visible.sync="dialogVisible" width="50%" :before-close="close">
    <el-form :model="qualityForm" :rules="rules" ref="qualityForm" label-width="110px">
      <el-form-item label="质检成果" prop="name">
        <el-input v-model="qualityForm.name" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="质检成果内容" prop="content">
        <el-input type="textarea" v-model="qualityForm.content" placeholder="请输入" :rows="4"></el-input>
      </el-form-item>
      <el-form-item label="质检成果数量" prop="taskCount">
        <div style="width:100%; display: flex;">
          <el-input-number v-model="qualityForm.taskCount" style="flex: 1;" :min="0" placeholder="请输入"></el-input-number>
          <el-dropdown trigger="click" @command="handleDownClick">
            <el-button style="width: 90px;">
              {{ qualityForm.taskUnit }}<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="item.label" v-for="item in dict.type.xmgl_task_unit" :key="item.value">
                {{ item.label }}
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-form-item>
      <el-form-item label="质检存放目录" prop="storagePath">
        <el-input v-model="qualityForm.storagePath" placeholder="请输入"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">保 存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  dicts: ['xmgl_task_unit'],
  data() {
    return {
      qualityForm: {
        taskUnit: '个'
      },
      title: '添加质检内容',
      dialogVisible: false,
      rules: {
        name: [{ required: true, message: '请输入质检名称', trigger: 'blur' }],
        storagePath: [{ required: true, message: '请输入质检存放路径', trigger: 'blur' }],
        taskCount: [{ required: true, message: '请输入质检成果数量', trigger: 'blur' }],
        taskUnit: [{ required: true, message: '请输入质检数量单位', trigger: 'blur' }],
        content: [{ required: true, message: '请输入质检成果内容', trigger: 'blur' }],
      }
    };
  },

  mounted() {
  },

  methods: {
    open(data) {
      if (data) {
        this.qualityForm = JSON.parse(JSON.stringify(data));
        this.title = '编辑质检内容';
      } else {
        this.title = '添加质检内容';
      }
      this.dialogVisible = true;
    },
    // 产值单位赋值
    handleDownClick(value) {
      this.$set(this.qualityForm, 'taskUnit', value);
    },
    close() {
      this.$refs.qualityForm.resetFields();
      this.dialogVisible = false;
      this.qualityForm = this.$options.data().qualityForm;
    },
    save() {
      this.$refs.qualityForm.validate((valid) => {
        if (valid) {
          if (this.qualityForm.guid) {
            this.$emit('editTableData', Object.assign({}, this.qualityForm));
          } else {
            this.qualityForm.guid = this.$guid();
            this.$emit('addTableData', Object.assign({}, this.qualityForm));
          }
          this.close();
        } else {
          this.$modal.msgError('请填写完完整信息！');
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
